import {
  queryOrderStat
} from '../../api/store.js';
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    parameter: {
      'navbar': '1',
      'return': '0',
      'title': '个人中心',
      'color': true,
      'class': '0'
    },
    userInfo: {},
    MyMenus: [],
    isGoIndex: false,
    iShidden: true,
    isAuto: false,
    switchActive: false,
    loginType: app.globalData.loginType,
    orderStatusNum: {},//订单信息
  },

  close: function() {
    this.setData({
      switchActive: false
    });
  },
  /**
   * 授权回调
   */
  onLoadFun: function(e) {
    this.getUserInfo();
    this.queryOrderStat();
    //this.getMyMenus();
  },
  /**
   * 
   * 获取个人中心图标
   */
  getMyMenus: function() {
    var that = this;
    if (this.data.MyMenus.length) return;
    getMenuList().then(res => {
      that.setData({
        MyMenus: res.data.routine_my_menus
      });
    });
  },
  /**
   * 获取个人用户信息
   */
  getUserInfo: function() {
    var that = this;
      that.setData({
        userInfo: app.globalData.userInfo,
        loginType: app.globalData.loginType
      });
  },
  /*
   * 获取用户的订单各个状态下的数量
   */
  queryOrderStat: function(){
    var that = this;
    queryOrderStat().then(res=>{
      this.setData({orderStatusNum:res.data});
    }).catch(err =>{
      app.Tips({
        title: err
      })
    })
   },
  /**
   * 页面跳转
   */
  goPages: function(e) {
    if (app.globalData.isLog) {
      if (e.currentTarget.dataset.url == '/packageB/user_spread_user/index' && this.data.userInfo.statu == 1) {
        if (!this.data.userInfo.is_promoter) return app.Tips({
          title: '您还没有推广权限！！'
        });
      }
      if (e.currentTarget.dataset.url == '/pages/logon/index') return this.setData({
        switchActive: true
      });
      wx.navigateTo({
        url: e.currentTarget.dataset.url
      })
    } else {
      this.setData({
        iShidden: false
      });
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      MyMenus: app.globalData.MyMenus
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
    this.setData({
      switchActive: false
    });
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },
  onShow: function() {
    let that = this;
    if (app.globalData.isLog) {
      this.getUserInfo();
      //this.getMyMenus();
    }
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },
})